package com.dsg.service.account.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsg.dao.account.DsgAccountCashMapper;
import com.dsg.dao.account.DsgAccountLedgerMapper;
import com.dsg.entity.account.DsgAccountCash;
import com.dsg.entity.account.DsgAccountLedger;
import com.dsg.service.account.IDsgAccountCashService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 油公司日結帳 服务实现类
 * </p>
 *
 * @author system
 * @since 2020-07-12
 */
@Service
public class DsgAccountCashServiceImpl extends ServiceImpl<DsgAccountCashMapper, DsgAccountCash> implements IDsgAccountCashService {

    @Autowired
    private DsgAccountLedgerMapper dsgAccountLedgerMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void reconciliation(DsgAccountCash dsgAccountCash) {
        //回填油公司日結帳對賬狀態
        dsgAccountCash = getById(dsgAccountCash.getOid());
        dsgAccountCash.setRecStatus(DsgAccountCash.AppStatus.reconciled.getCode());
        updateById(dsgAccountCash);
        //回填油公司總帳明細對賬狀態
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("PID", dsgAccountCash.getOid());
        DsgAccountLedger dsgAccountLedger = new DsgAccountLedger();
        dsgAccountLedger.setRecStatus(DsgAccountLedger.AppStatus.reconciled.getCode());
        dsgAccountLedgerMapper.update(dsgAccountLedger, queryWrapper);
    }
}
